<?php
namespace Admin\Model;
use Zend\Db\TableGateway\TableGateway;
use Zend\Debug\Debug;
class UserTable{
	protected $tableGateway;

	public function __construct(TableGateway $table){
		$this->tableGateway = $table;
	}

	public function fetchAll(){
		return $this->tableGateway->select();
	}

	public function getUser($id){
		$id = (int)$id;
		$rowset = $this->tableGateway->select(array('id'=>$id));
		return $rowset;
	}

	public function checkPassword($username = NULL, $password = NULL){
		if(!empty($username) && !empty($password)){
			$rowset = $this->tableGateway->select(array('username'=>$username));
			// $password truyen vao o dang cleartext
			if($rowset['password'] == md5($password))
				return true;
			else
				return false;
		}else{
			return false;
		}
	}
}